/*引用模块*/
var express = require('express');
var path = require('path');
var ejs = require('ejs');
/*实例化express对象*/
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.engine('html', ejs.__express);
app.set('view engine', 'html');
app.use(express.static(path.join(__dirname, 'public')));
var router = express.Router();
app.use(router);
var bodyParser = require('body-parser');
app.use(bodyParser.json({
    limit: '10mb'
}));
//这里指定参数使用 json 格式
app.use(bodyParser.urlencoded({
    extended: true,
    limit: '50mb'
}));
app.get('/', function (req, res) {
    res.render('index', {});
});
function getClientIp(req) {
    return req.headers['x-forwarded-for'] ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress;
};
var clientIp = require('client-ip');

app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
app.post('/test', function (req, res) {
    var gData = req.body;
    // var ip = getClientIp(req)
    var ip = clientIp(req);
    console.log(ip)
    res.send({msg:'获取消息成功',status:'200',data:{
        name:'你好'
    }})
})
app.listen(92);
console.log("启动成功92")